package stu.day25_day32.day25.day3;
import stu.day25_day32.day25.all.*;
public class hw2 {

    public static boolean x = true;


    public boolean isBalanced(TreeNode root) {
        height(root);
        return x;
    }


    public int height(TreeNode node){
        if(node==null){
            return 0;
        }
        int l = height(node.left);
        int r = height(node.right);

        if(Math.abs(l-r)>1){
            x = false;
        }
        int h = Math.max(l,r);

        return h+1;


    }

    class Solution {
        boolean res = true;

        public boolean isBalanced(TreeNode root) {
            int d = depth(root);
            return res;
        }

        public int depth(TreeNode root) {
            if (root == null) return 0;
            int left = depth(root.left);
            int right = depth(root.right);
            if (left - right > 1 || right - left > 1) res = false;
            return Math.max(left, right) + 1;
        }
    }


}
